//
//  NSObject+safeValue.m
//  SmartEstateCC
//
//  Created by 初唐科技 on 2018/8/30.
//  Copyright © 2018 pretang. All rights reserved.
//

#import "NSObject+safeValue.h"

@implementation NSObject (safeValue)

NSString *SafeValue(id value,NSString *notice,NSString *format)
{
    if (Safe(value)) {
        if (format) {
            return [NSString stringWithFormat:format,value];
        }
        return [NSString stringWithFormat:@"%@",value];
    }
    else
    {
        if (notice) {
            return notice;
        }
        return @"";
    }
}
BOOL Safe(id value)
{
    if (value == [NSNull null] || value == nil || value == Nil || [value isKindOfClass:[NSNull class]]) {
        return NO;
    }
    if ([value isKindOfClass:[NSString class]]) {
        NSString *str = (NSString *)value;
        if (str.length == 0 || [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length == 0 || [str stringByReplacingOccurrencesOfString:@" " withString:@""].length == 0 || [str isEqualToString:@"null"] || [str isEqualToString:@"<null>"] || [str isEqualToString:@"(null)"]) {
            return NO;
        }
    }
    
    return YES;
}

@end
